Fix typing contract for Blob client max_concurrency#45598
Merged
nateprewitt merged 4 commits intoAzure:mainfrom Mar 11, 2026
Merged
Fix typing contract for Blob client max_concurrency#45598nateprewitt merged 4 commits intoAzure:mainfrom
nateprewitt merged 4 commits intoAzure:mainfrom
Conversation
Member
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns the Blob client max_concurrency typing contract with the SDK’s long-standing runtime behavior by allowing None to mean “use the SDK default”, and centralizes that default into a shared constant.
Changes:
- Introduce
DEFAULT_MAX_CONCURRENCYand use it whenmax_concurrencyisNone. - Update sync/async downloaders and deprecated convenience methods to accept
max_concurrency=None. - Update sync/async
BlobClientstub typings toOptional[int] = None.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/storage/azure-storage-blob/azure/storage/blob/aio/_download_async.py | Accept Optional[int] for max_concurrency and default via DEFAULT_MAX_CONCURRENCY in async downloader paths. |
| sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.pyi | Updates public async stub signatures to Optional[int] = None. |
| sdk/storage/azure-storage-blob/azure/storage/blob/_shared/constants.py | Adds shared DEFAULT_MAX_CONCURRENCY constant. |
| sdk/storage/azure-storage-blob/azure/storage/blob/_download.py | Accept Optional[int] for max_concurrency and default via DEFAULT_MAX_CONCURRENCY in sync downloader paths. |
| sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client_helpers.py | Defaults max_concurrency to the shared constant when omitted/None in option builders. |
| sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.pyi | Updates public sync stub signatures to Optional[int] = None. |
Comments suppressed due to low confidence (2)
sdk/storage/azure-storage-blob/azure/storage/blob/aio/_download_async.py:843
- The deprecated methods now default
max_concurrencytoNone, but the docstrings still document it as:param int max_concurrency:without mentioning thatNoneis accepted and means “use the default”. Please update the docstrings (and/or type hints) to reflect the new Optional behavior so generated docs match the supported contract.
async def content_as_bytes(self, max_concurrency=None):
"""DEPRECATED: Download the contents of this file.
This operation is blocking until all data is downloaded.
This method is deprecated, use func:`readall` instead.
:param int max_concurrency:
The number of parallel connections with which to download.
:return: The contents of the file as bytes.
:rtype: bytes
"""
warnings.warn(
"content_as_bytes is deprecated, use readall instead",
DeprecationWarning
)
if self._text_mode:
raise ValueError("Stream has been partially read in text mode. "
"content_as_bytes is not supported in text mode.")
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
return await self.readall()
async def content_as_text(self, max_concurrency=None, encoding="UTF-8"):
"""DEPRECATED: Download the contents of this blob, and decode as text.
This operation is blocking until all data is downloaded.
This method is deprecated, use func:`readall` instead.
:param int max_concurrency:
The number of parallel connections with which to download.
sdk/storage/azure-storage-blob/azure/storage/blob/_download.py:900
- The deprecated methods now default
max_concurrencytoNone, but the docstrings still document it as:param int max_concurrency:without mentioning thatNoneis accepted and means “use the default”. Please update the docstrings (and/or type hints) to reflect the new Optional behavior so generated docs match the supported contract.
def content_as_bytes(self, max_concurrency=None):
"""DEPRECATED: Download the contents of this file.
This operation is blocking until all data is downloaded.
This method is deprecated, use func:`readall` instead.
:param int max_concurrency:
The number of parallel connections with which to download.
:return: The contents of the file as bytes.
:rtype: bytes
"""
warnings.warn(
"content_as_bytes is deprecated, use readall instead",
DeprecationWarning
)
if self._text_mode:
raise ValueError("Stream has been partially read in text mode. "
"content_as_bytes is not supported in text mode.")
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
return self.readall()
def content_as_text(self, max_concurrency=None, encoding="UTF-8"):
"""DEPRECATED: Download the contents of this blob, and decode as text.
This operation is blocking until all data is downloaded.
This method is deprecated, use func:`readall` instead.
:param int max_concurrency:
The number of parallel connections with which to download.
sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client_helpers.py
Show resolved
Hide resolved
sdk/storage/azure-storage-blob/azure/storage/blob/aio/_download_async.py
Show resolved
Hide resolved
sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client_helpers.py
Outdated
Show resolved
Hide resolved
sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client_helpers.py
Outdated
Show resolved
Hide resolved
8a3543e to
250bea3
Compare
Member
jalauzon-msft
left a comment
There was a problem hiding this comment.
Thanks for taking care of this! Approach looks good if you were planning to replicate elsewhere.
sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client_helpers.py
Show resolved
Hide resolved
weirongw23-msft
approved these changes
Mar 10, 2026
This was referenced Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This is 1 of 3 PRs to address inconsistent typing across the Storage APIs. While working on typing for a project (adlfs) that uses the Azure Python SDK, we found our long standing pattern of passing
Nonewhen deferring the decision to the SDK doesn't match the type contract on the SDK.Despite the stub file, the SDK does handle
Nonecorrectly for the majority of the public blob, file-datalake, and file-share APIs. It's also typed inconsistently with some APIs already beingOptional[int], and others only allowingint.This PR consolidates behavior to be consistent across all Blob APIs and unifies the max_concurrency default concept on a shared
DEFAULT_MAX_CONCURRENCYconstant. Once we agree on what's required to get this merged, I can replicate to the other clients. For testing, there's not a great way to test this through the public APIs. The changes are very narrow and there are existing tests that already exercise the default path. I can add more though if it's deemed necessary.I also updated the deprecated methods that use
max_concurrencyto keep everything consistent. If we'd like to leave those untouched, I can remove those changes.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines